package com.egao.ap.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.ap.entity.InformationZan;
import com.egao.ap.service.InformationZanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 点赞
 * @author : Doman
 * @date : 2020-10-23 23:27:18
 * @version ：1.0
 */

@Api(tags = "点赞")
@RestController
@RequestMapping("/api/ap/informationZan")
public class InformationZanController extends BaseController {

	@Autowired
	private InformationZanService informationZanService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('ap:informationZan:list')")
    @ApiOperation("分页查询点赞")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, InformationZan informationZan) throws Exception{
        return informationZanService.list(page, informationZan, getLoginUser());
    }

    /**
     * 查询全部点赞
     */
    @PreAuthorize("hasAuthority('ap:informationZan:list')")
    @ApiOperation("查询全部点赞")
    @PostMapping("/list")
    public JsonResult list(InformationZan informationZan){
        return informationZanService.list(informationZan, getLoginUser());
    }

    /**
     * 根据id查询点赞
     */
    @PreAuthorize("hasAuthority('ap:informationZan:list')")
    @ApiOperation("根据id查询点赞")
    @PostMapping("/get")
    public JsonResult get(InformationZan informationZan) {
        return informationZanService.getById(informationZan);
		// 使用关联查询
        //PageParam<informationZan> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<informationZan> records = informationZanService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加点赞
     */
    @PreAuthorize("hasAuthority('ap:informationZan:save')")
    @OperLog(value = "点赞", desc = "添加", param = false, result = true)
    @ApiOperation("添加点赞")
    @PostMapping("/save")
    public JsonResult save(Model model, InformationZan informationZan) {
        return informationZanService.save(informationZan, getLoginUser());
    }

    /**
     * 修改点赞
     */
    @PreAuthorize("hasAuthority('ap:informationZan:update')")
    @OperLog(value = "点赞", desc = "修改", param = false, result = true)
    @ApiOperation("修改点赞")
    @PostMapping("/update")
    public JsonResult update(Model model, InformationZan informationZan) {
        return informationZanService.update(informationZan, getLoginUser());
    }

    /**
     * 删除点赞
     */
    @PreAuthorize("hasAuthority('ap:informationZan:remove')")
    @OperLog(value = "点赞", desc = "删除", result = true)
    @ApiOperation("删除点赞")
    @PostMapping("/remove")
    public JsonResult remove(InformationZan informationZan ) {
        return informationZanService.remove(informationZan, getLoginUser());
    }

    /**
     * 批量添加点赞
     */
    /**@RequiresPermissions("ap:informationZan:save")
    @OperLog(value = "点赞", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<InformationZan> list) {
        if (informationZanService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改点赞
     */
    /**@RequiresPermissions("ap:informationZan:update")
    @OperLog(value = "点赞", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<InformationZan> batchParam) {
        if (batchParam.update(informationZanService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除点赞
     */
    /**@RequiresPermissions("ap:informationZan:remove")
    @OperLog(value = "点赞", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (informationZanService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
